package com.woniu.zsd.recycle.controller;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.zsd.common.util.Result;
import com.woniu.zsd.recycle.form.AddTypeForm;
import com.woniu.zsd.recycle.form.SelectTypeForm;
import com.woniu.zsd.recycle.model.MaterialType;
import com.woniu.zsd.recycle.param.AddTypeParam;
import com.woniu.zsd.recycle.param.SelectTypeParam;
import com.woniu.zsd.recycle.service.MaterialTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 彭于晏
 * @since 2025年02月18日
 */
@RestController
@RequestMapping("/materialType")
@Api(tags = "废品分类管理")
public class MaterialTypeController {
    @Resource
    private MaterialTypeService materialTypeService;
    @PostMapping("/selectTypeTree")
    @ApiOperation("查询类别树")
    public Result selectTypeTree()throws Exception{
        return Result.success("查询类别树成功",materialTypeService.selectMaterialTypeTree());
    }
    @PostMapping("/addType")
    @ApiOperation("新增类别")
    public Result addType(@RequestBody AddTypeForm form)throws Exception{
        materialTypeService.add(BeanUtil.toBean(form, AddTypeParam.class));
        return Result.success("新增类别成功",null);
    }
    @PostMapping("/selectType")
    @ApiOperation("根据条件查询全部类别")
    public Result selectType(@RequestBody SelectTypeForm form)throws Exception{
        Page<MaterialType> materialTypePage = materialTypeService.selectType(BeanUtil.toBean(form, SelectTypeParam.class));

        return Result.success("查询全部类别成功",materialTypePage);
    }
    @PostMapping("/disable")
    @ApiOperation("禁用类别")
    public Result disable(Integer materialTypeId)throws Exception{
        materialTypeService.disable(materialTypeId);
        return Result.success("禁用类别成功",null);
    }
    @PostMapping("/enable")
    @ApiOperation("启用类别")
    public Result enable(Integer materialTypeId)throws Exception{
        materialTypeService.enable(materialTypeId);
        return Result.success("启用类别成功",null);
    }
    @PostMapping("/delete")
    @ApiOperation("删除类别")
    public Result delete(Integer materialTypeId)throws Exception{
        materialTypeService.delete(materialTypeId);
        return Result.success("删除类别成功",null);
    }
    @PostMapping("/userSelectType")
    @ApiOperation("用户查询回收站废品类型")
    public Result userSelectType()throws Exception{
        materialTypeService.userSelectType();
        return Result.success("删除类别成功",null);
    }
}

